<html>
<head><meta charset="utf-8"><title>Getting the symbol name of an intrinsic? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html">Getting the symbol name of an intrinsic?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="201375884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201375884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201375884">(Jun 19 2020 at 11:01)</a>:</h4>
<p>Hi everyone,</p>
<p>I need to find the symbol name for a call to an intrinsic inside from inside <code>rustc_codegen_llvm</code>.</p>
<p>For example, in a little debug build of a program I wrote, <code>wrapping_add</code> for <code>u32</code> codegens to a call to the symbol:</p>
<div class="codehilite"><pre><span></span><code>core::num::_&lt;impl u32&gt;::wrapping_add::h0d270c55aeefd2ff
</code></pre></div>


<p>I have the <code>Instance</code> and argument types of the intrinsic to hand.</p>
<p>Unfortunately, <code>tcx.symbol_name</code> doesn't seem to work on intrinsics.</p>
<p>Is there way to do this in the compiler? If not, is there an LLVM API call I could use to get it from the raw LLVM pointer for the intrinsic?</p>
<p>Thanks!</p>



<a name="201376147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376147">(Jun 19 2020 at 11:04)</a>:</h4>
<p>Intrinsics don't have symbols, that's what makes them instrinsics. <code>core::num::_&lt;impl u32&gt;::wrapping_add::h0d270c55aeefd2ff</code> is the symbol for the <code>u32::wrapping_add</code> wrapper.</p>



<a name="201376166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376166">(Jun 19 2020 at 11:04)</a>:</h4>
<p>Intrinsics don't have symbol names. They are never codegened. Any mir calls to intrinsics are translated by the codegen backend to specific instruction sequences. For example <code>wrapping_add</code> turns into a LLVM add instruction.</p>



<a name="201376220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376220">(Jun 19 2020 at 11:05)</a>:</h4>
<p>Is it possible to get the symbol name of the wrapper?</p>



<a name="201376268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376268">(Jun 19 2020 at 11:06)</a>:</h4>
<p>Only if you know what the wrapper is.</p>



<a name="201376270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376270">(Jun 19 2020 at 11:06)</a>:</h4>
<p>An intrinsics can be wrapped by multiple function.</p>



<a name="201376434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376434">(Jun 19 2020 at 11:08)</a>:</h4>
<p>I'm in <code>codegen_intrinsic_call()</code> in <code>librustc_codegen_llvm/intrinsic.rs</code>. I'm not sure if I have sufficient information to find the wrapper. In fact, it looks to me like it builds a call directly to the intrinsic?</p>



<a name="201376493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376493">(Jun 19 2020 at 11:09)</a>:</h4>
<p>That function matches on the intrinsic and then depending on the intrinsic codegens different code.</p>



<a name="201376598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376598">(Jun 19 2020 at 11:10)</a>:</h4>
<p>Yes, but I don't see any mention of wrappers. It looks to me like it just emits an LLVM intrinsic call to <code>llvm.x.y</code>.</p>



<a name="201376616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376616">(Jun 19 2020 at 11:11)</a>:</h4>
<p>Some rust intrinsics are lowered to LLVM intrinsics, while others are lowered to regular LLVM instructions.</p>



<a name="201376642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376642">(Jun 19 2020 at 11:11)</a>:</h4>
<p>yea, but llvm codegens that in "arbitrary" ways, usually just to raw asm instructions, not to function calls</p>



<a name="201376665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376665">(Jun 19 2020 at 11:11)</a>:</h4>
<p>oh you're inside codegen_llvm</p>



<a name="201376669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376669">(Jun 19 2020 at 11:11)</a>:</h4>
<p>nevermind me</p>



<a name="201376732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376732">(Jun 19 2020 at 11:12)</a>:</h4>
<p>what do you need the symbol name of the wrapper for?</p>



<a name="201376793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376793">(Jun 19 2020 at 11:13)</a>:</h4>
<p><span class="user-mention silent" data-user-id="223288">Edd Barrett</span> Is working on an <a href="https://github.com/softdevteam/ykrustc/">alternative codegen backend</a> that is a tracing jit. He probably wants to avoid having to implement all intrinsics by hand for now by calling functions instead.</p>



<a name="201376809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376809">(Jun 19 2020 at 11:13)</a>:</h4>
<p>To add a little context, we are writing a tracing JIT for Rust. We've JITted a call to <code>wrapping_add</code>, which gets turned into a call to a symbol in our IR.</p>
<p>I'm starting to wonder if we need to implement our own intrinsics in the JIT.</p>
<p>And what <span class="user-mention" data-user-id="133247">@bjorn3</span> said :)</p>



<a name="201376929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376929">(Jun 19 2020 at 11:15)</a>:</h4>
<p>not all intrinsics even have wrappers. <code>transmute</code> is directly invoked, there's no wrapper</p>



<a name="201376954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376954">(Jun 19 2020 at 11:15)</a>:</h4>
<p>ok, but all non-<code>transmute</code> intrinsics have wrappers</p>



<a name="201376975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201376975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201376975">(Jun 19 2020 at 11:15)</a>:</h4>
<p>you can make the wrappers lang items, but that's a lot of lang items <span aria-label="confused" class="emoji emoji-1f615" role="img" title="confused">:confused:</span></p>



<a name="201377038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201377038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201377038">(Jun 19 2020 at 11:16)</a>:</h4>
<p>a hacky way would be to use paths to get the <code>DefId</code> of the wrappers and then compute the symbol name</p>



<a name="201377131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201377131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201377131">(Jun 19 2020 at 11:18)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust-clippy/blob/742706511c9f33c6a0d4380392e513e5249057e3/clippy_lints/src/utils/mod.rs#L252">https://github.com/rust-lang/rust-clippy/blob/742706511c9f33c6a0d4380392e513e5249057e3/clippy_lints/src/utils/mod.rs#L252</a></p>



<a name="201377149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201377149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201377149">(Jun 19 2020 at 11:18)</a>:</h4>
<p>not great, but should allow you to progress immediately without having to do much groundwork</p>



<a name="201377168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201377168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201377168">(Jun 19 2020 at 11:18)</a>:</h4>
<p>Maybe creating an <code>Instance</code> with <code>InstanceDef::ReifyShim</code> pointing to the intrinsic will work? You would need to extend the mono item collector to generate appropriate <code>InstanceDef::ReifyShim</code> for all intrinsics when used though.</p>



<a name="201377208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201377208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201377208">(Jun 19 2020 at 11:19)</a>:</h4>
<p>You should then skip SIR generation for those intrinsic <code>ReifyShim</code>'s and use the <code>ReifyShim</code> symbol_name when generating SIR for intrinsic calls.</p>



<a name="201377297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201377297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201377297">(Jun 19 2020 at 11:21)</a>:</h4>
<p>(For those not familiar with the tracing JIT of <span class="user-mention silent" data-user-id="223288">Edd Barrett</span>, SIR is the IR produced by the codegen backend and consumed by the JIT itself)</p>



<a name="201377325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201377325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201377325">(Jun 19 2020 at 11:21)</a>:</h4>
<p>OK, I understood <span class="user-mention" data-user-id="124288">@oli</span>'s suggestion.</p>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> Can you expand upon:</p>
<blockquote>
<p>You would need to extend the mono item collector to generate appropriate InstanceDef::ReifyShim for all intrinsics when used though.</p>
</blockquote>
<p>Thanks</p>



<a name="201377338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201377338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201377338">(Jun 19 2020 at 11:22)</a>:</h4>
<p>yea I think the reifyshim solution (if it works) is the better one</p>



<a name="201377389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201377389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201377389">(Jun 19 2020 at 11:22)</a>:</h4>
<p>if it doesn't work, it's likely not hard to make it work</p>



<a name="201377407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201377407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201377407">(Jun 19 2020 at 11:22)</a>:</h4>
<p>In <code>rustc_mir::monomorphize::collector</code> all mono items that need to be codegened are collected. You would need to extend it to create a <code>ReifyShim</code> mono item for every intrinsic call.</p>



<a name="201377548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201377548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201377548">(Jun 19 2020 at 11:24)</a>:</h4>
<p>You should add a line like <a href="https://github.com/rust-lang/rust/blob/a39c7787ba246353178e099373b9240be0d9e603/src/librustc_mir/monomorphize/collector.rs#L743">https://github.com/rust-lang/rust/blob/a39c7787ba246353178e099373b9240be0d9e603/src/librustc_mir/monomorphize/collector.rs#L743</a> at <a href="https://github.com/rust-lang/rust/blob/a39c7787ba246353178e099373b9240be0d9e603/src/librustc_mir/monomorphize/collector.rs#L726">https://github.com/rust-lang/rust/blob/a39c7787ba246353178e099373b9240be0d9e603/src/librustc_mir/monomorphize/collector.rs#L726</a> for <code>InstanceDef::Intrinsic</code>. Take care to change the <code>instance</code> to be a <code>ReifyShim</code> instead of an <code>Intrinsic</code> though.</p>



<a name="201377558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201377558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201377558">(Jun 19 2020 at 11:24)</a>:</h4>
<p>I see.</p>
<p>Thanks everyone. This has been very useful.</p>
<p>I need to weigh up <span class="user-mention" data-user-id="133247">@bjorn3</span>'s solution, vs. implementing our own intrinsics. In the long run we probably want the latter, as we want as few calls in our trace as possible. But, as you say, that's a <em>lot</em> of intrinsics!</p>



<a name="201397386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201397386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201397386">(Jun 19 2020 at 14:29)</a>:</h4>
<p>If I understand correctly, this is the modification we need is something like:</p>
<div class="codehilite"><pre><span></span><code>    match instance.def {
        ty::InstanceDef::Intrinsic(_) =&gt; {
            output.push(create_fn_mono_item(
                Instance {
                    def: InstanceDef::ReifyShim(instance.def_id()),
                    substs: instance.substs,
                }
            ))
        },
        ty::InstanceDef::Virtual(..) =&gt; {
            if !is_direct_call {
                bug!(&quot;{:?} being reified&quot;, instance);
            }
        }
...
</code></pre></div>


<p>But this will give crashes as the compiler builds itself:</p>
<div class="codehilite"><pre><span></span><code>symbol `add_with_overflow` is already defined
</code></pre></div>


<p>Also tried monomorphising the instance first:</p>
<div class="codehilite"><pre><span></span><code>    match instance.def {
        ty::InstanceDef::Intrinsic(_) =&gt; {
            let callee_ty = instance.monomorphic_ty(tcx);
            if let ty::FnDef(def_id, substs) = callee_ty.kind {
                output.push(create_fn_mono_item(
                    Instance {
                        def: InstanceDef::ReifyShim(def_id),
                        substs,
                    }
                ))
            } else {
                bug!(&quot;xxx&quot;);
            }
        },
</code></pre></div>


<p>Same outcome.</p>
<p>Is there any hope?</p>
<p>EDIT: maybe only push if the item is not yet present? EDIT EDIT: Nope.</p>



<a name="201512126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201512126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201512126">(Jun 21 2020 at 02:42)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F/near/201376954">said</a>:</p>
<blockquote>
<p>ok, but all non-<code>transmute</code> intrinsics have wrappers</p>
</blockquote>
<p>The wrapers aren't necessarily direct calls to intrinsics either, however, and the intrinsics can be called directly. So there may be cases where a call of an intrinsic cannot map to any wrapper.</p>



<a name="201512196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201512196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201512196">(Jun 21 2020 at 02:43)</a>:</h4>
<p>/me says before reading the rest of the thread</p>



<a name="201524362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20symbol%20name%20of%20an%20intrinsic%3F/near/201524362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20symbol.20name.20of.20an.20intrinsic.3F.html#201524362">(Jun 21 2020 at 08:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="223288">Edd Barrett</span> and I have talked about this in PM.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>